package com.freedom.service.core;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.freedom.bean.core.SysUser;
import com.freedom.bean.core.TestTable;
import com.freedom.dao.core.SysUserDao;
import com.freedom.exception.RTServiceExcepton;
import com.freedom.sys.UserUtils;
import com.freedom.util.sys.DateTimeUtil;
import com.freedom.util.usually.FileUploadUtil;
import com.freedom.vo.w.core.SysUserVo;

/**
 * 用户service
 * @author HGJ
 *
 */
@Transactional
@Service
public class SysUserService {

	@Autowired
	private SysUserDao sysUserDao; //用户dao

	/**
	 * 登录校验
	 * @param username
	 * @return
	 */
	public SysUser checkUserByName(String userName) {
		return sysUserDao.checkUserByName(userName);
	}
	
	/**
	 * 获取用户列表
	 * @param map
	 * @return
	 */
	public List<SysUser> getUserList(Map<String, Object> map){
		return sysUserDao.getUserList(map);
	}

	/*
	 * 测试数据使用
	 */
	public List<TestTable> getTest1List(Map<String, Object> map) {
		return sysUserDao.getTest1List(map);
	}

	/**
	 * 添加用户信息
	 * @param file
	 * @param param
	 * @return
	 */
	public SysUserVo saveSysUser(HttpServletRequest request, SysUserVo param) throws RTServiceExcepton{
		// TODO Auto-generated method stub
		SysUserVo vo = new SysUserVo();
		String photo = FileUploadUtil.uploadFiles(request, "E:\\");
		SysUser user = new SysUser();
		user.setName(param.getName());
		user.setLoginName(param.getLoginName());
		user.setPassword(param.getPassword());
		user.setAge(param.getAge());
		user.setSex(param.getSex());
		user.setEmail(param.getEmail());
		user.setPhone(param.getPhone());
		user.setAddress(param.getAddress());
		user.setPhone(photo);
		user.setCreateDate(DateTimeUtil.getSystemDateTime());
		user.setCreateBy(UserUtils.getUser());
		vo.setErrCode("0");
		vo.setMsg("操作成功");
		//vo.setMsg("操作失败");	
		return vo;
	}
}
